<template>
	<div class="page">
		<Notice></Notice>
		<u-navbar :is-back="true" title="全局设置"></u-navbar>
		<u-tabs :list="tabs" :is-scroll="false" :current="tabIndex" @change="tabChange" bg-color="#F0F0F0"></u-tabs>
		<u-subsection style="margin-top: 20rpx;" v-show="tabIndex==0" :list="subs" :current="subIndex" @change="subChange" bg-color="#FFFFFF" active-color="#1E62FC" button-color="#F0F0F0"></u-subsection>
		
		<!-- 倾向性规则 -->
		<div class="content-1" v-show="tabIndex==0 && subIndex==0">
			<u-alert-tips type="primary" title="正面词规则对信息倾向性进行研判，与系统判断规则同时生效，并优先系统规则。" style="margin: 10rpx;"></u-alert-tips>
			<div class="block" style="border: none;">
				<div class="title">关键词一<span class="red">*</span></div>
				<div class="box" @click="toInputPage('正面词-关键词一')">
					<div class="tags" v-if="params.positive_words_1.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.positive_words_1" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">关键词二</div>
				<div class="box" @click="toInputPage('正面词-关键词二')">
					<div class="tags" v-if="params.positive_words_2.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.positive_words_2" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">关键词三</div>
				<div class="box" @click="toInputPage('正面词-关键词三')">
					<div class="tags" v-if="params.positive_words_3.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.positive_words_3" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">排除词</div>
				<div class="box" @click="toInputPage('正面词-排除词')">
					<div class="tags" v-if="params.positive_exclude_words.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.positive_exclude_words" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">歧义词</div>
				<div class="box" @click="toInputPage('正面词-歧义词')">
					<div class="tags" v-if="params.positive_confused_words.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.positive_confused_words" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
		</div>
		<div class="content-1" v-show="tabIndex==0 && subIndex==1">
			<u-alert-tips type="primary" title="负面词规则对信息倾向性进行研判，与系统判断规则同时生效，并优先系统规则。" style="margin: 10rpx;"></u-alert-tips>
			<div class="block" style="border: none;">
				<div class="title">关键词一<span class="red">*</span></div>
				<div class="box" @click="toInputPage('负面词-关键词一')">
					<div class="tags" v-if="params.negative_words_1.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.negative_words_1" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">关键词二</div>
				<div class="box" @click="toInputPage('负面词-关键词二')">
					<div class="tags" v-if="params.negative_words_2.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.negative_words_2" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">关键词三</div>
				<div class="box" @click="toInputPage('负面词-关键词三')">
					<div class="tags" v-if="params.negative_words_3.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.negative_words_3" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">排除词</div>
				<div class="box" @click="toInputPage('负面词-排除词')">
					<div class="tags" v-if="params.negative_exclude_words.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.negative_exclude_words" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">歧义词</div>
				<div class="box" @click="toInputPage('负面词-歧义词')">
					<div class="tags" v-if="params.negative_confused_words.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.negative_confused_words" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
		</div>
		<!-- 排除规则 -->
		<div class="content-2" v-show="tabIndex==1">
			<div class="block" style="border: none;">
				<div class="title">排除词<span class="red">*</span></div>
				<div class="box" @click="toInputPage('排除词')">
					<div class="tags" v-if="params.exclude_words.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.exclude_words" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">排除域名</div>
				<div class="box" @click="toInputPage('排除域名')">
					<div class="tags" v-if="params.exclude_domain.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.exclude_domain" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">排除频道</div>
				<div class="box" @click="toInputPage('排除频道')">
					<div class="tags" v-if="params.exclude_channel.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.exclude_channel" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">排除作者</div>
				<div class="box" @click="toInputPage('排除作者')">
					<div class="tags" v-if="params.exclude_author.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.exclude_author" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
		</div>
		<!-- 过滤规则 -->
		<div class="content-3" v-show="tabIndex==2">
			<div class="block">
				<div class="title">过滤域名</div>
				<div class="box" @click="toInputPage('过滤域名')">
					<div class="tags" v-if="params.filter_domain.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.filter_domain" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">过滤频道</div>
				<div class="box" @click="toInputPage('过滤频道')">
					<div class="tags" v-if="params.filter_channel.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.filter_channel" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">过滤作者</div>
				<div class="box" @click="toInputPage('过滤作者')">
					<div class="tags" v-if="params.filter_author.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.filter_author" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
		</div>

		<div class="option">
			<div class="option-b flex">
				<div class="l" @click="isDes=true">
					<u-icon name="question-circle" size="36" color="#999" style="margin-right: 10rpx;"></u-icon>
					说明
				</div>
				<div class="r">
					<u-button type="primary" @click="save">保存</u-button>
				</div>
			</div>
		</div>
		<!-- 说明 -->
		<u-popup v-model="isDes" mode="bottom" border-radius="14">
			<view class="des">
				<div class="top"><u-icon class="icon" name="arrow-down" size="32" @click="isDes=false"></u-icon> 说明</div>
				<scroll-view scroll-y="true" class="container" v-if="tabIndex==0">
					<div class="title">关键词</div>
					<div class="text">
						<div>1.可输入多个关键词，词与词之间为“或”关系，多组为“与”关系。</div>
						<div>2.输入不能包含特殊字符“<>!'”。</div>
					</div>
					<div class="title">排除词</div>
					<div class="text">
						<div>1.命中关键词的信息，将不进入系统。</div>
						<div>2.可输入多个关键词，词之间以空格间隔，词与词之间为“或”关系。</div>
						<div>3.输入不能包含特殊字符“<>!'"。</div>
					</div>
					<div class="title">歧义词</div>
					<div class="text">
						<div>1.与关键词相歧义的词，如品牌词为邯郸，歧义为邯郸学步。命中关键词的信息，将参考其它关键词的命中概率，再决定是否进入系统。</div>
						<div>2.可输入多个关键词，词之间以空格间隔，词与词之间为“或”关系。</div>
						<div>3.输入不能包含特殊字符“<>!'"</div>
					</div>
				</scroll-view>
				<scroll-view scroll-y="true" class="container" v-if="tabIndex==1">
					<div class="title">排除词</div>
					<div class="text">
						<div>1.命中关键词的信息，将不进入系统。</div>
						<div>2.可输入多个关键词，词之间以空格间隔，词与词之间为“或”关系。</div>
						<div>3.输入不能包含特殊字符“<>|'”。</div>
					</div>
					<div class="title">排除域名</div>
					<div class="text">
						<div>1.域名网站发布的信息，将不进入系统。</div>
						<div>2.现有特殊校验字符<>|。</div>
					</div>
					<div class="title">排除频道</div>
					<div class="text">
						<div>1.网站频道发布的信息，将不进入系统。</div>
						<div>2.现有特殊校验字符<>|。</div>
					</div>
					<div class="title">排除作者</div>
					<div class="text">
						<div>1.作者发布的信息，将不进入系统。</div>
						<div>2.现有特殊校验字符<>|。</div>
					</div>
				</scroll-view>
				<scroll-view scroll-y="true" class="container" v-if="tabIndex==2">
					<div class="title">过滤域名</div>
					<div class="text">
						<div>1.域名网站发布的信息，将会被过滤。</div>
						<div>2.现有特殊校验字符<>|。</div>
						<div>3.在筛选条件中，噪音过滤中选择“过滤”，即可查看已过滤信息。</div>
					</div>
					<div class="title">过滤频道</div>
					<div class="text">
						<div>1.网站频道发布的信息，将会被过滤。</div>
						<div>2.现有特殊校验字符<>|。</div>
						<div>3.在筛选条件中，噪音过滤中选择“过滤”，即可查看已过滤信息。</div>
					</div>
					<div class="title">过滤作者</div>
					<div class="text">
						<div>1.作者发布的信息，将会被过滤。</div>
						<div>2.现有特殊校验字符<>|。</div>
						<div>3.在筛选条件中，噪音过滤中选择“过滤”，即可查看已过滤信息。</div>
					</div>
				</scroll-view>
			</view>
		</u-popup>
			
		<wordInput v-if="isInputPage" :flag="kwType" @sendKeyWords="getWordData"></wordInput>
		<u-toast ref="uToast" />
	</div>
</template>

<script>
import wordInput from "@/components/wordInput.vue";
import { commonDetail, commonSave } from "@/api/subject.js";
	
export default {
	components: {
		wordInput,
	},
	data() {
		return {
			tabs: [
				{
					name: "倾向性规则"
				}, {
					name: "排除规则"
				}, {
					name: "过滤规则",
				},
			],
			tabIndex: 0,
			subs: [
				{
					name: "正面词"
				}, 
				{
					name: "负面词"
				}, 
			],
			subIndex: 0,
			isDes: false,
			kwType: "",
			params: {
				positive_words_1: [],
				positive_words_2: [],
				positive_words_3: [],
			
				positive_exclude_words: [],
				positive_confused_words: [],
			
				negative_words_1: [],
				negative_words_2: [],
				negative_words_3: [],
			
				negative_exclude_words: [],
				negative_confused_words: [],
			
				exclude_words: [],
				exclude_domain: [],
				exclude_channel: [],
				exclude_author: [],
			
				filter_domain: [],
				filter_channel: [],
				filter_author: [],
				filter_similar: [],
			}
		};
	},
	computed: {
		isInputPage() {
			return this.$store.state.isInputPageInAdd;
		},
	},
	mounted() {
		commonDetail().then(({code, data})=>{
			if(code == 200 && JSON.stringify(data) != "{}"){
				Object.keys(data).map(key => {
					this.params[key] = data[key];
				});
			}
		})
	},
	methods: {
		tabChange(index) {
			this.tabIndex = index;
		},
		subChange(index) {
			this.subIndex = index;
		},
		getWordData(data) {
			switch(data.type){
				case "正面词-关键词一": 
					this.params.positive_words_1 = data.content.split(" ");
					break;
				case "正面词-关键词二":
					this.params.positive_words_2 = data.content.split(" ");
					break;
				case "正面词-关键词三":
					this.params.positive_words_3 = data.content.split(" ");
					break;
				case "正面词-排除词":
					this.params.positive_exclude_words = data.content.split(" ");
					break;
				case "正面词-歧义词":
					this.params.positive_confused_words = data.content.split(" ");
					break;
				case "负面词-关键词一": 
					this.params.negative_words_1 = data.content.split(" ");
					break;
				case "负面词-关键词二":
					this.params.negative_words_2 = data.content.split(" ");
					break;
				case "负面词-关键词三":
					this.params.negative_words_3 = data.content.split(" ");
					break;
				case "负面词-排除词":
					this.params.negative_exclude_words = data.content.split(" ");
					break;
				case "负面词-歧义词":
					this.params.negative_confused_words = data.content.split(" ");
					break;
					
				case "排除词":
					this.params.exclude_words = data.content.split(" ");
					break;
				case "排除域名":
					this.params.exclude_domain = data.content.split(" ");
					break;
				case "排除频道":
					this.params.exclude_channel = data.content.split(" ");
					break;
				case "排除作者":
					this.params.exclude_author = data.content.split(" ");
					break;
					
				case "过滤域名":
					this.params.filter_domain = data.content.split(" ");
					break;
				case "过滤频道":
					this.params.filter_channel = data.content.split(" ");
					break;
				case "过滤作者":
					this.params.filter_author = data.content.split(" ");
					break;
			}
		},
		toInputPage(type) {
			this.kwType = type;
			switch(type){
				case "正面词-关键词一": 
					this.$store.commit("inputPageWordHandle", this.params.positive_words_1.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "正面词-关键词二": 
					this.$store.commit("inputPageWordHandle", this.params.positive_words_2.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "正面词-关键词三":
					this.$store.commit("inputPageWordHandle", this.params.positive_words_3.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "正面词-排除词":
					this.$store.commit("inputPageWordHandle", this.params.positive_exclude_words.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "正面词-歧义词":
					this.$store.commit("inputPageWordHandle", this.params.positive_confused_words.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "负面词-关键词一":
					this.$store.commit("inputPageWordHandle", this.params.negative_words_1.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "负面词-关键词二": 
					this.$store.commit("inputPageWordHandle", this.params.negative_words_2.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "负面词-关键词三":
					this.$store.commit("inputPageWordHandle", this.params.negative_words_3.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "负面词-排除词":
					this.$store.commit("inputPageWordHandle", this.params.negative_exclude_words.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "负面词-歧义词":
					this.$store.commit("inputPageWordHandle", this.params.negative_confused_words.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				
				case "排除词":
					this.$store.commit("inputPageWordHandle", this.params.exclude_words.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "排除域名":
					this.$store.commit("inputPageWordHandle", this.params.exclude_domain.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "排除频道":
					this.$store.commit("inputPageWordHandle", this.params.exclude_channel.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "排除作者":
					this.$store.commit("inputPageWordHandle", this.params.exclude_author.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
					
				case "过滤域名":
					this.$store.commit("inputPageWordHandle", this.params.filter_domain.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "过滤频道":
					this.$store.commit("inputPageWordHandle", this.params.filter_channel.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "过滤作者":
					this.$store.commit("inputPageWordHandle", this.params.filter_author.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
			}
			this.$store.commit("isInputPageInAddHandle", true);
		},
		save() {
			// if(!this.params.positive_words_1.length){
			// 	this.$refs.uToast.show({
			// 		title: "请输入必填关键词",
			// 		type: "error",
			// 	});
			// }
			commonSave(this.params).then(({code})=>{
				if(code === 200){
					this.$refs.uToast.show({
						title: "保存成功",
						type: "success",
					});
					setTimeout(()=>{
						uni.navigateBack({
							delta: 1,
						});
					}, 1000);
				}
			});
		},
		
	}
}
</script>

<style lang="scss">
@import "@/style/globalSetting.scss";
</style>
